﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using System.Xml;
using DataLayer;


namespace DataImporterConsole.Screens {
    public class IntroScreen : Screen {
        private List<char> validInput = new List<char>(new char[1] { '1' });

        public override void Display() {
            Console.WriteLine(string.Format(screenbase, "\t[1] Create Sample Spell data \r\n"));
        }

        public override bool isValidInput(char cki) {
            return validInput.Contains(cki);
        }

        public override void Action(char cki) {
            switch (cki) {
                case '1':
                    CreateBasicSpellFile();
                    break;
                default:
                    break;
            }

            Environment.Exit(0);
        }

        public string InputError {
            get { return "Input error, try again: "; }
        }

        private void CreateBasicSpellFile() {
            DataSpell[] spellarray = new DataSpell[2];

            DataSpell spell = new DataSpell();
            spell.CastingTime = 2.0;
            spell.Coefficient = 0.7;
            spell.OTCoefficient = 0.3;
            spell.Cooldown = 0;
            spell.CostType = CostType.Fixed;
            spell.DirectMeanValue = 1892.5;
            spell.DirectMeanRange = 677.5;
            spell.Duration = 21.0;
            spell.ManaCost = 675;
            spell.Name = "Regrowth";
            spell.OvertimeValue = 182;
            spell.Rank = 10;
            spell.SchoolUsed = SpellSchool.Nature;
            spell.SpellType = SpellType.Heal;
            spell.TicksLength = 3.0;

            DataSpell otherspell = new DataSpell();
            otherspell.CastingTime = 3.5;
            otherspell.Coefficient = 1;
            otherspell.CostType = CostType.Fixed;
            otherspell.Cooldown = 0;
            otherspell.DirectMeanValue = 2952;
            otherspell.DirectMeanRange = 245;
            otherspell.Duration = 0;
            otherspell.ManaCost = 935;
            otherspell.Name = "Healing Touch";
            otherspell.OvertimeValue = 0;
            otherspell.Rank = 13;
            otherspell.SchoolUsed = SpellSchool.Nature;
            otherspell.SpellType = SpellType.Heal;
            otherspell.TicksLength = 0;

            spellarray[0] = spell;
            spellarray[1] = otherspell;

            XmlSerializer ser = new XmlSerializer(typeof(DataSpell[]));
            FileStream fs = new FileStream(@"C:\Private\Code\datafiles\onespell.xml", FileMode.Create);
            //XmlTextWriter textWriter = new XmlTextWriter(fs, Encoding.UTF8);

            //ser.Serialize(textWriter, spell);
            ser.Serialize(fs, spellarray);
            fs.Close();
        }
    }
}
